import pymysql


def main():
    conn = pymysql.connect(host='47.92.100.143', port=3306, user='root', password='123456', db='school',
                           charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute('insert into tb_student values(1008,"周芷若 ",0,"2022-2-2","河南郑州")')
            if result == 1:
                print('添加成功')
                conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        # 语句很多的时候 前面的语句执行成功 后面失败 rollback可以撤销前面成功语句的操作
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    main()
